<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="title">
            <h2><a href="#" class="back" onclick="history.go(-1)"/>Pesquisar Ficha de Inscrição</h2>
        </ui:define>

        <ui:define name="body">

            <h:form id="form" enctype="multipart/form-data">            
                <p:messages id="messages" closable="true" showDetail="true" autoUpdate="true"  />

                <p:panel styleClass="container_24 clearfix">
                    <div class="buttonAction" style="float: right">
                        <p:commandButton value="Crachá" actionListener="#{managerPesquisarFichaInscricao.imprimirNomesCracha()}"
                                         ajax="false" onclick="this.form.target='_blank'" update="@form"
                                         icon="ui-icon-print" immediate="true" />

                        <p:commandButton value="Nomes" process="@form"
                                         oncomplete="relatorioDlg.show()"
                                         icon="ui-icon-print"/>

                        <p:button value="Adicionar" href="criarfichainscricao.xhtml" icon="ui-icon-plusthick"
                                  styleClass="ui-priority-primary"/>
                    </div>
                    <br/>
                </p:panel>

                <p:panel styleClass="container_24 clearfix">

                    <h2>Participante</h2>
                    <p:outputLabel value="Tipo:" styleClass="grid_3" for="tipoParticipante"/>
                    <div class="grid_8 select-one-menu">
                        <p:selectOneMenu id="tipoParticipante" panelStyle="width:150px;"
                                         value="#{managerPesquisarFichaInscricao.ficha.tipoParticipante}">
                            <f:selectItem itemLabel="" itemValue="" />
                            <f:selectItems value="#{managerUtilitario.tipoParticipante}"/>
                        </p:selectOneMenu>
                    </div>

                    <p:outputLabel value="Status:" styleClass="grid_3" for="status"/>
                    <div class="grid_8 select-one-menu statusSelectOneMenu">
                        <p:selectOneMenu id="status" panelStyle="width:150px;"
                                         value="#{managerPesquisarFichaInscricao.ficha.status}">
                            <f:selectItem itemLabel="" itemValue="" />
                            <f:selectItems value="#{managerUtilitario.status}"/>
                        </p:selectOneMenu>
                    </div>
                    <div class="clear"/>

                    <p:outputLabel value="Nome: " styleClass="grid_3"/>
                    <p:inputText styleClass="grid_19" value="#{managerPesquisarFichaInscricao.ficha.participante.nome}"/>
                    <div class="clear"/>

                    <p:outputLabel value="Endereço:" styleClass="grid_3"/>
                    <p:inputText styleClass="grid_19" value="#{managerPesquisarFichaInscricao.ficha.participante.enderecoSimples}"/>
                    <div class="clear"/>

                    <p:outputLabel value="Clube:" styleClass="grid_3" for="clube"/>
                    <p:autoComplete id="clube" styleClass="grid_8 clubeAutocompletePesquisar" dropdown="true" converter="clubeconverter"
                                    var="clube" itemLabel="#{clube.nome.toString().concat(' - ').concat(clube.estado.sigla)}"
                                    itemValue="#{clube}" value="#{managerPesquisarFichaInscricao.ficha.clube}"
                                    scrollHeight="200" forceSelection="true"
                                    completeMethod="#{managerUtilitario.autocompleteClube}"/>

                    <p:outputLabel value="Meio de Transporte:" styleClass="grid_5 alpha transporte1025" for="meioTransporte"/>
                    <p:outputLabel value="Transporte:" styleClass="grid_5 alpha transporte1024" for="meioTransporte"/>
                    <div class="grid_7 select-one-menu meioTransporteSelectOneMenuPesquisar">
                        <p:selectOneMenu id="meioTransporte" panelStyle="width:150px;"
                                         value="#{managerPesquisarFichaInscricao.ficha.meioTransporte}">
                            <f:selectItem itemLabel="" itemValue="" />
                            <f:selectItems value="#{managerUtilitario.meioTransporte}"/>
                        </p:selectOneMenu>
                    </div>
                    <div class="clear"/>

                    <h2>Convidado</h2>
                    <p:outputLabel value="Tipo:" styleClass="grid_3" for="tipoConvidado"/>
                    <div class="grid_8 select-one-menu">
                        <p:selectOneMenu id="tipoConvidado" panelStyle="width:150px;"
                                         value="#{managerPesquisarFichaInscricao.ficha.tipoConvidado}">
                            <f:selectItem itemLabel="" itemValue="" />
                            <f:selectItems value="#{managerUtilitario.tipoConvidado}"/>
                        </p:selectOneMenu>
                    </div>
                    <div class="clear"/>

                    <p:outputLabel value="Nome:" styleClass="grid_3" for="nomeConvidado"/>
                    <p:inputText id="nomeConvidado" styleClass="grid_20" value="#{managerPesquisarFichaInscricao.ficha.convidado.nome}"/>
                    <div class="clear"/>

                    <div class="clear"/>

                    <div class="buttonAction">
                        <p:commandButton id="bt_pesquisar" value="Pesquisar" icon="ui-icon-search"
                                         update="resultadoTable"
                                         actionListener="#{managerPesquisarFichaInscricao.pesquisar()}"
                                         styleClass="ui-priority-primary" />
                        <p:commandButton id="limpar" value="Limpar" icon="ui-icon-close"
                                         update="@form"
                                         actionListener="#{managerPesquisarFichaInscricao.init()}"/>
                    </div>

                </p:panel>

                <p:panel styleClass="container_24 clearfix">
                    <p:dataTable id="resultadoTable" var="item" value="#{managerPesquisarFichaInscricao.dataModel}" 
                                 styleClass="grid_24" rowIndexVar="rowid"
                                 binding="#{managerPesquisarFichaInscricao.searchResults}"
                                 rows="5" paginator="true" lazy="true"   
                                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                                 currentPageReportTemplate="{currentPage} de {totalPages}"
                                 paginatorPosition="bottom" emptyMessage="Nenhum registro encontrado">

                        <f:facet name="header">
                            <p:outputLabel value="Resultados #{managerPesquisarFichaInscricao.searchResults.rowCount eq 0 ? '' : '('.concat(managerPesquisarFichaInscricao.searchResults.rowCount).concat(')')}" />
                        </f:facet>
                        <p:column headerText="Ação" width="80" > 
                            <p:button title="Visualizar" icon="ui-icon-zoomin"
                                      href="visualizarfichainscricao.xhtml?ficha=#{item.id}"/>
                            <p:commandButton title="Excluir" oncomplete="dlg.show();" update="@form" 
                                             icon="ui-icon-trash">
                                <f:setPropertyActionListener target="#{managerPesquisarFichaInscricao.fichaExcluir}" value="#{item}" />
                            </p:commandButton>
                        </p:column>
                        <p:column headerText="Participante">
                            <p:outputLabel value="#{item.participante.nome}"/>
                        </p:column>
                        <p:column headerText="Tipo">
                            <p:outputLabel value="#{item.tipoParticipante.nome}"/>
                        </p:column>
                        <p:column headerText="Clube" style="text-align: center"> 
                            <p:outputLabel value="#{item.clube.nome.concat(' - ').concat(item.clube.estado.nome).concat('/').concat(item.clube.estado.sigla)}"/>
                        </p:column>
                        <p:column headerText="Status" style="text-align: center"> 
                            <p:outputLabel value="#{item.status.nome}"/>
                        </p:column>

                    </p:dataTable>
                </p:panel>

                <div class="buttonAction">
                    <p:button href="criarfichainscricao.xhtml" value="Cancelar" icon="ui-icon-circle-close"/>
                </div>

                <p:dialog id="exclusaoDialog" header="Exclusão" widgetVar="dlg" closable="true"
                          appendToBody="true" closeOnEscape="true" modal="true" resizable="false" height="80">
                    <h:outputText value="Deseja excluir essa Ficha de Inscrição ?" /> <br/> 

                    <div class="buttonAction">
                        <p:commandButton value="Sim" update="@form" icon="ui-icon-check"
                                         actionListener="#{managerPesquisarFichaInscricao.remover()}"/>
                        <p:commandButton value="Não" process="@this" onclick="dlg.hide()" icon="ui-icon-close" />
                    </div>
                </p:dialog>

                <p:dialog id="relatorioDialog" header="Relatório" widgetVar="relatorioDlg" closable="true"
                          closeOnEscape="true" resizable="false" height="80">

                    <div class="buttonAction">
                        <p:commandButton value="Por Clube" actionListener="#{managerPesquisarFichaInscricao.imprimirRelacaoClube()}"
                                         ajax="false" onclick="this.form.target='_blank'" onkeyup="relatorioDlg.hide()"
                                         update="@form"
                                         icon="ui-icon-print" immediate="true" />

                        <p:commandButton value="Geral" actionListener="#{managerPesquisarFichaInscricao.imprimirRelacaoGeral()}"
                                         ajax="false" onclick="this.form.target='_blank'" onkeyup="relatorioDlg.hide()"
                                         icon="ui-icon-print" immediate="true" />
                    </div>
                </p:dialog>

            </h:form>
        </ui:define>
    </ui:composition>
</html>
